package com.ruoyi.system.service.impl;


import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.system.domain.GxAssess;
import com.ruoyi.system.mapper.GxAssessMapper;
import com.ruoyi.system.service.IGxAssessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * assessService业务层处理
 * 
 * @author ruoyi
 * @date 2022-04-24
 */
@Service
public class GxAssessServiceImpl implements IGxAssessService 
{
    @Autowired
    private GxAssessMapper gxAssessMapper;

    /**
     * 查询assess
     * 
     * @param assessId assess主键
     * @return assess
     */
    @Override
    public GxAssess selectGxAssessByAssessId(Long assessId)
    {
        return gxAssessMapper.selectGxAssessByAssessId(assessId);
    }

    /**
     * 查询assess列表
     * 
     * @param gxAssess assess
     * @return assess
     */
    @Override
    public List<GxAssess> selectGxAssessList(GxAssess gxAssess)
    {
        return gxAssessMapper.selectGxAssessList(gxAssess);
    }


    public List<GxAssess> selectAssessesByUserId(Long userId)
    {
        List<GxAssess> userAssesses = gxAssessMapper.selectAssessPermissionByUserId(userId);
        List<GxAssess> assesses = selectGxAssessList(new GxAssess());
        for (GxAssess assess : assesses)
        {
            for (GxAssess userAssess : userAssesses)
            {
                if (assess.getAssessId().longValue() == userAssess.getAssessId().longValue())
                {
                    assess.setFlag(true);
                    break;
                }
            }
        }
        return assesses;
    }

    public List<GxAssess> selectAssessesByDeptId(Long deptId) {
        List<GxAssess> deptAssesses = gxAssessMapper.selectAssessPermissionByDeptId(deptId);
        List<GxAssess> assesses = selectGxAssessList(new GxAssess());
        for (GxAssess assess : assesses)
        {
            for (GxAssess deptAssess : deptAssesses)
            {
                if (assess.getAssessId().longValue() == deptAssess.getAssessId().longValue())
                {
                    assess.setFlag(true);
                    break;
                }
            }
        }
        return assesses;
    }

    public List<GxAssess> selectAssessAll()
    {
        return SpringUtils.getAopProxy(this).selectGxAssessList(new GxAssess());
    }
    /**
     * 新增assess
     * 
     * @param gxAssess assess
     * @return 结果
     */
    @Override
    public int insertGxAssess(GxAssess gxAssess)
    {
        gxAssess.setCreateTime(DateUtils.getNowDate());
        return gxAssessMapper.insertGxAssess(gxAssess);
    }

    /**
     * 修改assess
     * 
     * @param gxAssess assess
     * @return 结果
     */
    @Override
    public int updateGxAssess(GxAssess gxAssess)
    {
        gxAssess.setUpdateTime(DateUtils.getNowDate());
        return gxAssessMapper.updateGxAssess(gxAssess);
    }

    /**
     * 批量删除assess
     * 
     * @param assessIds 需要删除的assess主键
     * @return 结果
     */
    @Override
    public int deleteGxAssessByAssessIds(Long[] assessIds)
    {
        return gxAssessMapper.deleteGxAssessByAssessIds(assessIds);
    }

    /**
     * 删除assess信息
     * 
     * @param assessId assess主键
     * @return 结果
     */
    @Override
    public int deleteGxAssessByAssessId(Long assessId)
    {
        return gxAssessMapper.deleteGxAssessByAssessId(assessId);
    }
}
